<?php

use yii\db\Migration;

class m181111_122152_create_card_daily_usage extends Migration
{
    public function safeUp()
    {
        $this->createTable('{{%card_daily_usage}}', [
            'id' => $this->primaryKey(),
            'card_id' => $this->integer()->notNull()->comment('卡编号'),
            'date' => $this->char(8)->notNull()->comment('日期'),
            'data' => $this->decimal(20, 4)->notNull()->defaultValue(0)->comment('数据用量（B）'),
            'sms' => $this->integer()->notNull()->defaultValue(0)->comment('短信用量（条）'),
            'voice' => $this->integer()->notNull()->defaultValue(0)->comment('语音用量（分钟）'),
        ]);
        $this->createIndex('fk_card_daily_usage_card1_idx', '{{%card_daily_usage}}', ['card_id']);
        $this->addForeignKey('fk_card_daily_usage_card1', '{{%card_daily_usage}}', ['card_id'], '{{%card}}', ['id']);
        $this->createIndex('card_daily_usage_CD_idx', '{{%card_daily_usage}}', ['card_id', 'date'], true);
    }

    public function safeDown()
    {
        $this->dropTable('{{%card_daily_usage}}');
    }
}
